﻿#region File Description
///////////////////////////////////////////////////////////////////////////////
/// \file Button.cs
/// \brief This file stores the Button Class
/// \note It handles simple Button functionality and properties
/// \author Steven Duda 
/// \date 19/5/2010
/// \remarks Copyright(c) 2010 LM01 Project Group (Animus Games - ViralFlux)
/// \remarks Some Rights Reserved.
/// Licenced under: Microsoft Reciprocal License (Ms-RL)
/// For More Information see: www.microsoft.com/opensource/licenses.mspx
///////////////////////////////////////////////////////////////////////////////
#endregion

#region Using Statements
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
#endregion

namespace GameOfLife
{

    /// <summary>
    /// \class Button
    /// \author Steven Duda
    /// \brief This is a very simple Button Class. 
    /// \note Sealed Keyword can be removed if Overriding Button Class.
    /// </summary>
    internal sealed class Button
    {
        #region Fields
        internal Texture2D Texture { private set; get; }  ///< Button Texture used to Render 
        internal Vector2 Position { private set; get; }   ///< Button Position in 2D space.
        internal Color TintColor { private set; get; }    ///< Button TintColor Overlay 
        internal bool Enabled { set; get; }               ///< Is the Button Enabled                               

        #endregion

        /// \brief Constructor
        /// \note Loads a (2D Image) Texture and 2D InitialPosition (Vector2:x,y)
        /// \author Steven Duda
        internal Button(Texture2D texture, Vector2 initialPosition)
        {
            this.Texture = texture;
            this.Position = initialPosition;
            this.TintColor = Color.White;
            this.Enabled = true;
        }

        #region Public Methods

        /// \brief Draws the Button using texture and position
        /// \param batch The SpriteBatch used to Draw the Button Object
        /// \author Steven Duda
        internal void Draw(SpriteBatch batch)
        {
            batch.Draw(Texture, Position, TintColor);
        }

        /// \brief Updates the Button
        /// \note Handles Mouse over Button, and Enabled State
        /// \author Steven Duda
        internal void Update()
        {
            if (!Enabled)
                TintColor = Color.Black;
            else if (isMouseOver())
                TintColor = Color.LightGray;
            else
                TintColor = Color.White;
        }

        /// \brief Checks if the Mouse Pointers is on the Button
        /// \author Steven Duda
        /// \return  Target within the Button bounds? (true/false)
        internal bool isMouseOver()
        {
            return ((MouseStateManager.x >= Position.X) &&
                    (MouseStateManager.x <= (Position.X + Texture.Width)) &&
                    (MouseStateManager.y >= Position.Y) &&
                    (MouseStateManager.y <= (Position.Y + Texture.Height)));
        }

        /// \brief Checks if the Left Mouse Button is released on the Button
        /// \author Steven Duda
        /// \return Returns bool, Left Mouse Release on Button? (true/false)
        internal bool isReleased()
        {
            return (isMouseOver() && MouseStateManager.LeftButtonRelease());
        }

        /// \brief Checks if the Left Mouse is pressed on the Button
        /// \author Steven Duda
        /// \return Returns bool, Left Mouse Pressed on Button? (true/false)
        internal bool isPressed()
        {
            return (isMouseOver() && MouseStateManager.LeftButtonPress());
        }

        /// \brief Checks if the Right Mouse is held down on the Button
        /// \author Steven Duda
        /// \return Returns bool, Right Mouse held down On Button? (true/false)
        internal bool isRightHeld()
        {
            return (isMouseOver() && MouseStateManager.RightButtonHeld());
        }

        /// \brief Checks if the Right Mouse Button is released on the Button
        /// \author Steven Duda
        /// \return Returns bool, Right Mouse Release on Button? (true/false)
        internal bool isRightReleased()
        {
            return (isMouseOver() && MouseStateManager.RightButtonRelease());
        }

        /// \brief Checks if the Middle Mouse Button is released on the Button
        /// \author Steven Duda
        /// \return Returns bool, Middle Mouse Release on Button? (true/false)
        internal bool isMiddleReleased()
        {
            return (isMouseOver() && MouseStateManager.MiddleButtonRelease());
        }

        #endregion
    }
}
